package com.qs.javame.collection;

public class Test {

    public static void main(String[] args) {
//        System.out.println(3 & 15);
//        System.out.println(10 & 15);
//
//        System.out.println(0x31 & 0x0f);
//
//        System.out.println(0x31);
//        System.out.println(binaryToDecimal(49));

        String binStr = number2Binary(49);
        System.out.println(binStr);

        String s = Integer.toString(49, 16);
        System.out.println(s);
    }

    public static String binaryToDecimal(int n) {
        StringBuilder sb = new StringBuilder();

        for (int i = 7; i >= 0; i--) {
//            System.out.println(n >>> i);
            sb.append(n >>> i & 1);
        }

        return sb.toString();
    }

    public static String number2Binary(int n) {
        int t = 0;
        int r = 0;
        int result = 0;
        while (n != 0) {
            r = n % 2;
            n = n / 2;

            //System.out.println(n + "," + r + "," + Math.pow(10, t));
            result += r * Math.pow(10, t);
            t++;
        }

        return String.valueOf(result);
    }
}
